package org.gwtEss.client;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.gwtEss.client.messages.FlashMsg;
import org.gwtEss.client.window.PopupWindow;
import org.gwtEss.gwtExtensions.EnhancedFlexTable;
import org.gwtEss.gwtExtensions.FlexEventsTable;
import org.gwtEss.gwtExtensions.FocusableDateBox;
import org.gwtEss.menu.HasSelectableCallback;
import org.gwtEss.menu.Menu;
import org.gwtEss.menu.MenuItem;
import org.gwtEss.menu.MenuItemBase;
import org.gwtEss.menu.MenuItemSeperator;
import org.gwtEss.menu.MenuItemTitle;
import org.gwtEss.menu.SubMenuItemWidget;
import org.gwtEss.menu.SubMenuItems;
import org.gwtEss.other.DraggableWidget;
import org.gwtEss.other.H;
import org.gwtEss.other.HasWidgetResizerRequiredHandlers;
import org.gwtEss.other.NewPortletContainer;
import org.gwtEss.other.WidgetResizer;
import org.gwtEss.portlet.Portlet;
import org.gwtEss.portlet.PortletAdapter;
import org.gwtEss.portlet.PortletContainer;
import org.gwtEss.table.ClientSideTableAdapter;
import org.gwtEss.table.ColWidget;
import org.gwtEss.table.Cols;
import org.gwtEss.table.FetchCompleteCallBack;
import org.gwtEss.table.FilterMenuItem;
import org.gwtEss.table.HeaderTable;
import org.gwtEss.table.OnDemandTableAdapter;
import org.gwtEss.table.ReadOnlyTextColWidget;
import org.gwtEss.table.SmartUserManagedColWidget;
import org.gwtEss.table.SystemManagedColWidget;
import org.gwtEss.table.SystemManagedComparableColWidget;
import org.gwtEss.table.TextDesc;
import org.gwtEss.table.UserManagedColWidget;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
import com.google.gwt.user.datepicker.client.DatePicker;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GwtEss implements EntryPoint {
	public static final String[] colNames = {"read only column", "user defined column", "Smart user managed", "user defined column", "user managed text box col"};

	GreetingServiceAsync testService = GWT.create(GreetingService.class);
	FlexTable f = null; 
	public static LogPanel log = new LogPanel();
//	private int topHeight = 10;
	public void onModuleLoad() {
		
//		log.setWidth("100%");
//		log.setHeight("200px");
		
//	    RootPanel.get().add(initHeader());
//	    RootPanel.get().add(new PortletContainer());
		
//		RootPanel.get().add(test23());
//		RootPanel.get().add(test11());
//		RootPanel.get().add(test());
		
//		RootPanel.get().add(initPortlet343());
		
//		RootLayoutPanel.get().add(initNewPortlets());
		
//		RootPanel.get().add(new org.gwtEss.gwtExtensions.TextBox());
		
//		RootPanel.get().add(log);
//		RootPanel.get().add(initTab());
		
		
		final Widget t = initClientSideTab();
		RootPanel.get().add(t);
//		new WidgetResizer(t);
		
//		RootPanel.get().add(initTabHeader());
		
//		LayoutPanel lp = new LayoutPanel(){
//			@Override
//			public void onResize() {
//				Window.alert("resize");
//				super.onResize();
//			}
//		};
//		lp.add(new HTML("sdfdfdf"));
//		RootLayoutPanel.get().add(lp);
		
//		final SimpleTable st = new SimpleTable();
//		RootPanel.get().add(new VerticalPanel(){
//			{
//				FlexTable f; 
//				add(st);
//				st.setWidget();
//				add(new Button("sdsdsd", new ClickHandler() {
//					
//					@Override
//					public void onClick(ClickEvent event) {
//						Window.alert("" + st.getTdPxWidth());	
//					}
//				}));
//			}
//		});
		
		
//		RootLayoutPanel.get().add(new LayoutPanel(){
//			{
//				add(t);
//				setWidgetLeftRight(t, 10, Unit.PCT, 10, Unit.PCT);
//				setWidgetTopBottom(t, 10, Unit.PCT, 10, Unit.PCT);
//			}
//		});
//		RootPanel.get().add();
//		RootPanel.get().add(initMenu());
//		RootPanel.get().add(initResizePanel());

//		initLayoutPanel();
	}

	private Widget initNewPortlets() {
		return new DockLayoutPanel(Unit.PX){
			{
				addNorth(new HTML("north"), 25);
				addSouth(new HTML("south"), 25);
				add(new NewPortletContainer(){
					{
						
						addInColumn(0, new HTML("<div style='width:100%;height:100%;background-color:yellow'>sdfdf</div>"));
						addInColumn(0, new Button("some button"){
							{
								setSize("100%", "100%");
							}
						});
						addInColumn(1, new HTML("<div style='width:100%;height:100%;background-color:yellow'>sj sdjkh dksjfh dsjfhs djkfhs h sdfhsd hfd sfjd hjsdk sdjfh</div>"));
						addInColumn(1, new HTML("<div style='width:100%;height:100%;background-color:yellow'>hkajd hjkah kajhf kahajfhj kha fhdjfhj dfh</div>"));
						addInColumn(1, new HTML("<div style='width:100%;height:100%;background-color:yellow'>haskdjh fjkadh sdjkhdjkfh sdjkfh jksdjkhf sdjkfhdjkfh sdhsdfj sdfjh sdjkfhjk fshjkfhsd fjk</div>"));
						addInColumn(2, new HTML("<div style='width:100%;height:100%;background-color:yellow'>sjkl dfj ldjsdkl jklfj sljklfj sdljlsdjj sdj sdueou fkjiosrdujk fhsjkdhfsdhyf hkjsfhk sdfhjkfhsdjkfh fhsdjfhjkh</div>"));
						
					}
				});
			}
		};
}

	private Widget initTabHeader() {

		Cols<SimpleVO> cols = new Cols<SimpleVO>();

		
		ColWidget col1;
		cols.add(col1 = new ReadOnlyTextColWidget<SimpleVO>(colNames[0]){

			public TextDesc createDisplayText(SimpleVO data) {
				return new TextDesc(false, data.getStrCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}
/*
			public String defineColName() {
				return "read only column";
			}*/
			
		});
		
		cols.add(new SystemManagedColWidget<SimpleVO, TextBox>("System managed textbox"){

			@Override
			public TextBox createColWidgetInstance() {
				return new TextBox();
			}

			public TextDesc createDisplayText(SimpleVO data) {
				return new TextDesc(true, data.getStrCol());
			}

			@Override
			public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
				return UserTriggerEvent.MOUSE_MOVE;
			}

			@Override
			public boolean resetData(TextBox w, SimpleVO data) {
				data.setStrCol(w.getText());
				return true;
			}

			@Override
			public void resetWidget(SimpleVO data, TextBox w) {
				w.setText(data.getStrCol());
			}

			@Override
			public HorizontalAlignmentConstant alignment(SimpleVO data) {
				return HasHorizontalAlignment.ALIGN_CENTER;
			}
			
		});
		
		cols.add(new UserManagedColWidget<SimpleVO, CheckBox>(colNames[1], 30){

			public CheckBox createColWidgetInstance(final SimpleVO data) {
				final CheckBox chk = new CheckBox();
				chk.setValue(data.getIntCol() > 10);
				chk.addClickHandler(new ClickHandler(){

					public void onClick(ClickEvent event) {
						data.setIntCol(chk.getValue()?5:12);
					}
					
				});
				return chk;
			}
			
			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_CENTER;
			}

			/*public String defineColName() {
				return "user defined column";
			}*/
			
		});
		
		cols.add(new SmartUserManagedColWidget<SimpleVO, TextBox>(colNames[2] ){

			public TextBox createColWidgetInstance() {
				return new TextBox();
			}

			public boolean resetData(TextBox w, SimpleVO data) {
				data.setStrCol(w.getText());
				return true;
			}

			public void resetWidget(SimpleVO data, TextBox w) {
				w.setText(data.getStrCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}
/*
			public String defineColName() {
				return "Smart user managed";
			}
			*/
		});
		cols.add(new SystemManagedColWidget<SimpleVO, FocusableDateBox>(colNames[3]){

			public FocusableDateBox createColWidgetInstance() {
				return new FocusableDateBox();
			}

			public TextDesc createDisplayText(SimpleVO data) {
				Date date = data.getDateCol();
				return new TextDesc(false, date == null?"":date.toString());
			}

			public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
				return UserTriggerEvent.MOUSE_CLICK;
			}

			public boolean resetData(FocusableDateBox w, SimpleVO data) {
				data.setDateCol(w.getValue());
				return false;
			}

			public void resetWidget(SimpleVO data, FocusableDateBox w) {
				w.setValue(data.getDateCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}
/*
			public String defineColName() {
				return "user defined column";
			}
			*/
		});
		
		cols.add(new UserManagedColWidget<SimpleVO, TextBox>(colNames[4]){

			@Override
			public TextBox createColWidgetInstance(SimpleVO data) {
				TextBox t = new TextBox();
				t.setText(data.getStrCol());
				return t;
			}

		});
		return new HeaderTable<SimpleVO>(cols){

			@Override
			public void onColVisibilityChanged(Cols<SimpleVO> cols) {
				// TODO Auto-generated method stub
				
			}
			{
//				setPixelWidth(300);
			}
			@Override
			public void onFilterMenuClose(ColWidget col,
					List<FilterMenuItem> filterCriterias) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onFilterMenuSelect(ColWidget col,
					FetchCompleteCallBack<FilterMenuItem> filterListCallBack) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onResizeBegin(ColWidget leftCol, ColWidget rightCol) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onResizeEnd(ColWidget leftCol, ColWidget rightCol) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onSort(ColWidget col, Boolean asc) {
				// TODO Auto-generated method stub
				
			}
		};
	}

	private void initLayoutPanel() {
//		SplitLayoutPanel panel = new SplitLayoutPanel();
		HTML child0 = new HTML("child0");
		HTML child1 = new HTML("child1");
		HTML child2 = new HTML("child2");
		child1.addStyleName("detail11111");
		child2.addStyleName("detail11111");
//		panel.addWest(child1, 384);
//		panel.addNorth(child2, 100);
//		panel.add(new HTML("sdfdf"){
//			{
//				addStyleName("detail11111");
//			}
//		});
		
		
		LayoutPanelWithEvents p = new LayoutPanelWithEvents();
//		HTML whereAmI;
		
		final HTML whereAmI = new HTML("where the hell am i?"){
			{
				setSize("100px", "100px");
			}
		};
		DeferredCommand.add(new Command() {
			
			@Override
			public void execute() {
				DOM.setStyleAttribute(whereAmI.getElement(), "left", "100px");
				DOM.setStyleAttribute(whereAmI.getElement(), "top", "100px");
						
			}
		});
		
//		p.add(child0); p.add(child1); p.add(child2);
//
//		p.setWidgetLeftWidth(child0, 0, Unit.PCT, 50, Unit.PCT);  // Left panel
//		p.setWidgetRightWidth(child1, 0, Unit.PCT, 50, Unit.PCT); // Right panel
//
//		p.setWidgetLeftRight(child2, 5, Unit.EM, 5, Unit.EM);     // Center panel
//		p.setWidgetTopBottom(child2, 5, Unit.EM, 5, Unit.EM);
		
		p.add(whereAmI);
		
//		p.addStyleName("detail11111");

		p.setWidgetLeftRight(whereAmI, 5, Unit.EM, 5, Unit.EM);     // Center panel
//		p.setWidgetTopBottom(whereAmI, 5, Unit.EM, 5, Unit.EM);
		
		p.setWidgetLeftRight(whereAmI, 50, Unit.PX, 50, Unit.PX);     // Center panel
		p.setWidgetTopBottom(whereAmI, 50, Unit.PX, 50, Unit.PX);

		whereAmI.addStyleName("detail11111");
		new WidgetResizer((Widget)whereAmI);
		new DraggableWidget((Widget)whereAmI);
//		RootLayoutPanel.get().add(panel);
		RootLayoutPanel.get().add(p);
	
	}

	private class ResizablePopupPanel extends PopupPanel implements HasWidgetResizerRequiredHandlers{

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());
		}

	}
	private class ClientSideTableAdapterWithEvents<T> extends ClientSideTableAdapter<T> implements HasWidgetResizerRequiredHandlers{
		public ClientSideTableAdapterWithEvents(Cols cols, int pxWidth,
				int pxHeight, int rowsPerPage) {
			super(cols, pxWidth, pxHeight, rowsPerPage);
			// TODO Auto-generated constructor stub
		}

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	};
	private class LayoutPanelWithEvents extends LayoutPanel implements HasWidgetResizerRequiredHandlers{
		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	};
	private class DecoratorPanelWithEvents extends DecoratorPanel implements HasWidgetResizerRequiredHandlers{
		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	};
	private class DecoratedPopupPanelWithEvents extends PopupPanel implements HasWidgetResizerRequiredHandlers{
		
		
//		DecoratedPopupPanel dp = new DecoratedPopupPanel();
		DecoratorPanel dp = new DecoratorPanel();
		public DecoratedPopupPanelWithEvents() {
			super();
			setStyleName("resizePanel");
			super.setWidget(dp);
			
			dp.setSize("100%", "100%");
		}
		@Override
		public void setWidget(Widget w) {
			dp.setWidget(w);
		}
		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	};
	private abstract class PortletWithEvents extends Portlet implements HasWidgetResizerRequiredHandlers{

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	};
	private class SimplePanelWithEvents extends SimplePanel implements HasWidgetResizerRequiredHandlers{

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	}
	private class DatePickerWithEvents extends DatePicker implements HasWidgetResizerRequiredHandlers{

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	}

	private class ScrollPanelWithEvents extends ScrollPanel implements HasWidgetResizerRequiredHandlers{

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	}
	private class RichTextAreaWithEvents extends RichTextArea implements HasWidgetResizerRequiredHandlers{

		@Override
		public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
			return addDomHandler(handler, MouseDownEvent.getType());		
		}

		@Override
		public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
			return addDomHandler(handler, MouseMoveEvent.getType());
		}
		
	}
	private Widget initResizePanel() {
		
		
//		DockPanel hp = new DockPanel();
		
		FlowPanel hp = new FlowPanel();
		
		Widget left, right, center, sp1;
		hp.add(left = new ScrollPanelWithEvents(){
			{
				addStyleName("bord");
				setWidget(new HTML("sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>"));
//				setWidth("50px");
			}
		});
		hp.add(center = new ScrollPanelWithEvents(){
			{
				addStyleName("bord");
				setWidget(new HTML("sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>"));
			}
		});
		hp.add(new ScrollPanel(){
			{
				addStyleName("bord");
				setWidget(new HTML("sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>sjd fkjdklsjk f</br>"));
			}
		});
		hp.setWidth("100%");
		hp.add(right = new TextArea());
//		hp.setBorderWidth(1);
//		right.setWidth("100%");
//		hp.setWidth("100%");
		new WidgetResizer(left);
		new WidgetResizer(center);
		new WidgetResizer(right);
		return hp;
	}
	private Widget initResizePanel1() {
//		ResizableHTML html= new ResizableHTML("sdjls dlsk jskdjs lkdjs ldjsd sdj sdjls dlsk jskdjs lkdjs ldjsd sdj sdjls dlsk jskdjs lkdjs ldjsd sdj sdjls dlsk jskdjs lkdjs ldjsd sdj sdjls dlsk jskdjs lkdjs ldjsd sdj sdjls dlsk jskdjs lkdjs ldjsd sdj ");
//		HTML w = new HTML("sd fsdfh kdjfhs jkfhdjkf hdjsfhd f");
		org.gwtEss.other.HorizontalPanel w = new org.gwtEss.other.HorizontalPanel();
		w.add(new Label("sdsdfsdfsfsdf sd sfdf"));
		w.setBorderWidth(1);
		w.add(new TextArea(){
			{
				setSize("100%", "100%");
			}
		});
		WidgetResizer rw = new WidgetResizer((HasWidgetResizerRequiredHandlers)w);
//		w.setStyleName("resizePanel");
//		w.setSize("50px", "50px");
		return w; 
	}

	private Widget initMenu() {
		final Button button = new Button("V");
		final Label lab = new Label("test something");
//		new Menu((HasClickHandlers)lab);
		final Menu buttonMenu = new Menu() {
			
			@Override
			public int getMenuTop() {
				return button.getAbsoluteTop() + button.getOffsetHeight();
			}
			
			@Override
			public int getMenuLeft() {
				return button.getAbsoluteLeft();
			}
		};
		buttonMenu.setData(new ArrayList<MenuItemBase>(){
			{
				add(new MenuItem("some test menu item1"){
					{
						setIcon(new Image("images/silk/application.png"));
						setEnable(true);
						setSubMenu(new SubMenuItems(){
							{
								add(new MenuItem("dklfjdklfjd k11"){
									{
										setSubMenu(new SubMenuItemWidget<DatePicker>(){

											@Override
											public DatePicker createWidget(
													final HasSelectableCallback selectCallback) {

												return new DatePicker(){
													{
														addValueChangeHandler(new ValueChangeHandler<Date>() {
															
															@Override
															public void onValueChange(ValueChangeEvent<Date> event) {
																selectCallback.onSelect(true);
																FlashMsg.setMsg(new TextDesc(true, event.getValue().toString()));
															}
														});
													}
												};
											}
											
										});
//										setSubMenu(new SubMenuItemWidget<DatePicker>(new DatePicker()));
										
									}

									@Override
									public boolean onSelect() {
										return false;
									}
								});
								add(new MenuItem("dklfjdklfjd k12"){

									@Override
									public boolean onSelect() {
										FlashMsg.setMsg(new TextDesc(true, "dklfjdklfjd k12"));
										return true;
									}});
								add(new MenuItem("dklfjdklfjd k13"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("dklfjdklfjd k14"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("dklfjdklfjd k15"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("dklfjdklfjd k16"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
							}
						});
						setDetailText("Description Description  ");//TODO: Word wrap the description.  
					}

					@Override
					public boolean onSelect() {
						// TODO Auto-generated method stub
						return true;
					}
				});
				add(new MenuItem("some test menu item0"){
					{
						setIcon(new CheckBox());
						setDetailText("Some detail text for this menitem s.sdf.df. ");
						setToolTip("tooltip tooltip tooltip tooltip tooltip tooltip tooltip tooltip tooltip tooltip ");
						setEnable(true);
						setSubMenu(new SubMenuItems(){
							{
								add(new MenuItem("11"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}
									
								});
							}
						});
					}

					@Override
					public boolean onSelect() {
						// TODO Auto-generated method stub
						return true;
					}
				});
				add(new MenuItemSeperator());
				add(new MenuItem("inwerne rkekre krekre jrk"){

					@Override
					public boolean onSelect() {
						// TODO Auto-generated method stub
						return true;
					}
					
				});
				add(new MenuItem("inwerne rkekre krekre jrk"){

					@Override
					public boolean onSelect() {
						// TODO Auto-generated method stub
						return true;
					}});
				add(new MenuItemTitle("Header text"));
				add(new MenuItem("inwerne rkekre krekre jrk"){

					@Override
					public boolean onSelect() {
						FlashMsg.setMsg(new TextDesc(true, "inwerne rkekre krekre jrk"));
						return false;
					}});
				add(new MenuItem("inwerne rkekre krekre jrk"){
					{
						setEnable(false);
						setDetailText("some detail text that is diabled");
						setSubMenu(new SubMenuItems(){
							{
								add(new MenuItem("slkfj"){

									@Override
									public boolean onSelect() {
										FlashMsg.setMsg(new TextDesc(true, "Actually this item cannot be selected! "));
										return false;
									}});
							}
						});
					}

					@Override
					public boolean onSelect() {
						// TODO Auto-generated method stub
						return true;
					}
				});
				add(new MenuItem("inwerne rkekre krekre jrk"){

					@Override
					public boolean onSelect() {
						FlashMsg.setMsg(new TextDesc(true, "inwerne rkekre krekre jrk slkdjskl"));
						return false;
					}});
				add(new MenuItem("inwerne <b>rkekre krekre </b>jrk sdsdhkjhjkh"){

					@Override
					public boolean onSelect() {
						FlashMsg.setMsg(new TextDesc(true, "inwerne <b>rkekre krekre </b>jrk sdsdhkjhjkh"));
						return false;
					}});

				SubMenuItems emptySubMenu = new SubMenuItems();
				add(new MenuItem("empty sub menu", emptySubMenu){

					@Override
					public boolean onSelect() {
						FlashMsg.setMsg(new TextDesc(true, "empty sub menu"));
						return false;
					}});
				add(new MenuItem("some test menu item2"){
					{
						setSubMenu(new SubMenuItems(){
							{
								add(new MenuItem("20", new SubMenuItems()){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("21"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("22", new SubMenuItems(){
									{
										add(new MenuItem("221"){

											@Override
											public boolean onSelect() {
												// TODO Auto-generated method stub
												return true;
											}});
										add(new MenuItem("222"){

											@Override
											public boolean onSelect() {
												// TODO Auto-generated method stub
												return true;
											}});
										add(new MenuItem("223"){

											@Override
											public boolean onSelect() {
												// TODO Auto-generated method stub
												return true;
											}});
									}
								}){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("23", new SubMenuItems(){
									{
										add(new MenuItem("231"){

											@Override
											public boolean onSelect() {
												// TODO Auto-generated method stub
												return true;
											}});
										add(new MenuItem("232"){

											@Override
											public boolean onSelect() {
												// TODO Auto-generated method stub
												return true;
											}});
										add(new MenuItem("233", new SubMenuItems(){
											{
												add(new MenuItem("2331"){
													{
														setIcon(new RadioButton("rad"));
													}

													@Override
													public boolean onSelect() {
														// TODO Auto-generated method stub
														return true;
													}
												});
												add(new MenuItem("2332"){

													@Override
													public boolean onSelect() {
														// TODO Auto-generated method stub
														return true;
													}});
												add(new MenuItem("2333"){
													{
														setIcon(new RadioButton("rad"));
													}

													@Override
													public boolean onSelect() {
														// TODO Auto-generated method stub
														return true;
													}
												});
												add(new MenuItem("2334"){
													{
														setIcon(new RadioButton("rad"));
													}

													@Override
													public boolean onSelect() {
														// TODO Auto-generated method stub
														return true;
													}
												});
											}
										}){

											@Override
											public boolean onSelect() {
												// TODO Auto-generated method stub
												return true;
											}});
										
									}
								}){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
								add(new MenuItem("24"){

									@Override
									public boolean onSelect() {
										// TODO Auto-generated method stub
										return true;
									}});
							}
						});
					}

					@Override
					public boolean onSelect() {
						// TODO Auto-generated method stub
						return true;
					}
				});
			}
		});
		buttonMenu.setAnimationEnabled(true);
		buttonMenu.addAutoHidePartner(button.getElement());
		button.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				buttonMenu.show();
			}
		});
		return new HorizontalPanel(){
			{
				add(new CheckBox("auto fit"){
					{
						addClickHandler(new ClickHandler() {
							
							@Override
							public void onClick(ClickEvent event) {
								buttonMenu.setAutoFit(getValue());
							}
						});
					}
				});
				add(button);
				add(lab);
			}
		}; 
	}

	private Widget initPortlet() {
		/*Border b = new RoundBorder();
		b.setWidget(new Label("df kahf kjfh kdjf hdkjfh dkfh "));
		b.setSize("100px", "100px");
		return b; */
		
		PopupWindow win = new PopupWindow(){

			@Override
			public void onDrag(int mouseX, int mouseY) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onDragEnd(int mouseX, int mouseY) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onDragStart(int mouseX, int mouseY) {
				// TODO Auto-generated method stub
				
			}};
		win.setTitleWidget(new Label("some title widgetr", true));
//		win.setBodyWidget(new Label("djfkdlasfsdfdfdsdsfdsfsdfsfsdfsfsfsdfsfsfsdfsfsfsdfsdfsdsdfsdf dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd djfkdl dlkfd ", true));
		win.setBodyWidget(new org.gwtEss.gwtExtensions.TextBox());
//		win.setHeight("200px");
//		win.setWidth("200px");
		win.show();
		return new Label("sdsds");
	}
/*
	private Widget test23(){
		FilterMenu menu = new FilterMenu();
		ArrayList<FilterMenuItem> lst = new ArrayList<FilterMenuItem>();
		for (int i=0; i< 20; i++)
			lst.add(new FilterMenuItem("item " + i, i % 2 ==0));
		menu.setFilterList(lst);
		return menu;
	}*/
/*	private Widget test11() {
		HeaderTableColWidget w = new HeaderTableColWidget() {
		
			@Override
			public void onColResizeEnd() {
				// TODO Auto-generated method stub
		
			}
		
			@Override
			public void onColResizeBegin() {
				// TODO Auto-generated method stub
		
			}

			@Override
			public void onColSort(Boolean sortAsc) {
				// TODO Auto-generated method stub
				
			}
		};
		w.setHTML("some_text_columndlfh kdjhfj kdhfdjkfhdkj hkdjfhd kjfhjk");
		w.setWidth(50);
		w.setSeperatorVisible(true);
//		w.setSortOrder(false);
		w.setFilterMenuVisible(true);
		w.addStyleName("table-header");
		return w;
	}
*/
	private Widget test() {
		final EnhancedFlexTable f = new EnhancedFlexTable();
		final int rows = 40, cols = 10; 
		final long start = System.currentTimeMillis();
		for (int r = 0;r < rows; r++)
			for (int c = 0;c < cols; c++){
//				f.setText(r, c, (r + ", " + c));
				
				TextBox t = new TextBox();
				t.setText(r + ", " + c);				
				f.setWidget(r, c, t);
			}
		log.custom("test", "" + (System.currentTimeMillis() - start));
		return new VerticalPanel(){
			{
				add(f);
				add(new Button("change col", new ClickHandler(){

					public void onClick(ClickEvent event) {
						long start = System.currentTimeMillis();
						for (int r = 0;r < rows; r++){
							((TextBox)f.getWidget(r, 1)).setText("changed: " + r + ", " + 1);
//							f.setText(r, 1, ("changed: " + r + ", " + 1));
						}
						
						log.custom("test", "col chage:" + (System.currentTimeMillis() - start));
					}
					
				}));
				final TextBox column, width;
				add(column = new TextBox());
				add(width = new TextBox());
				add(new Button("change width", new ClickHandler(){

					public void onClick(ClickEvent event) {
						f.setColumnWidth(Integer.parseInt(column.getText()), Integer.parseInt(width.getText()));
					}
					
				}));
				
			}
		};
	}
	private Widget testFTable() {
		VerticalPanel v = new VerticalPanel();
		final FlexEventsTable f = new FlexEventsTable();
		final int rows = 200, cols = 20;
		for (int r = 0; r<rows; r++)
			for (int c= 0; c<rows; c++){
				TextBox t = new TextBox();
				t.setText("(" + r + "," + c + " )");
				f.setWidget(r, c, t);
			}
//				f.setText(r, c, "(" + r + "," + c + " )");
		final TextBox rowNum;
		v.add(rowNum = new TextBox());
		final CheckBox chk;
		v.add(chk = new CheckBox());
		v.add(new Button("show/hide col", new ClickHandler(){

			public void onClick(ClickEvent event) {
				long startTime = System.currentTimeMillis();
				for (int i=0; i<rows; i++){
					f.getCellFormatter().setVisible(i, Integer.parseInt(rowNum.getValue()), chk.getValue());
				}
				log.custom("time taken: ", "" + (System.currentTimeMillis() - startTime));
			}
			
		}));
		v.add(f);		
		return v;
	}
	/*public Widget initHeader(){
		
		Cols<SimpleVO> cols = new Cols<SimpleVO>();

		
		
		cols.add(new ReadOnlyTextColWidget<SimpleVO>("read only column"){

			public TextDesc createDisplayText(SimpleVO data) {
				return new TextDesc(false, data.getStrCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}

			public String defineColName() {
				return "read only column";
			}
			
		});
		
		cols.add(new UserManagedColWidget<SimpleVO, CheckBox>("user defined column", 30){

			public CheckBox createColWidgetInstance(final SimpleVO data) {
				final CheckBox chk = new CheckBox();
				chk.setValue(data.getIntCol() > 10);
				chk.addClickHandler(new ClickHandler(){

					public void onClick(ClickEvent event) {
						data.setIntCol(chk.getValue()?5:12);
					}
					
				});
				return chk;
			}
			
			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_CENTER;
			}

			public String defineColName() {
				return "user defined column";
			}
			
		});
		
		cols.add(new SmartUserManagedColWidget<SimpleVO, TextBox>( "Smart user managed"){

			public TextBox createColWidgetInstance() {
				return new TextBox();
			}

			public boolean resetData(TextBox w, SimpleVO data) {
				data.setStrCol(w.getText());
				return true;
			}

			public void resetWidget(SimpleVO data, TextBox w) {
				w.setText(data.getStrCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}

			public String defineColName() {
				return "Smart user managed";
			}
			
		});
		cols.add(new SystemManagedColWidget<SimpleVO, FocusableDateBox>("date col"){

			public FocusableDateBox createColWidgetInstance() {
				return new FocusableDateBox();
			}

			public TextDesc createDisplayText(SimpleVO data) {
				Date date = data.getDateCol();
				return new TextDesc(false, date == null?"":date.toString());
			}

			public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
				return UserTriggerEvent.MOUSE_CLICK;
			}

			public boolean resetData(FocusableDateBox w, SimpleVO data) {
				data.setDateCol(w.getValue());
				return false;
			}

			public void resetWidget(SimpleVO data, FocusableDateBox w) {
				w.setValue(data.getDateCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}

			public String defineColName() {
				return "user defined column";
			}
			
		});
		HeaderTable<SimpleVO> h = new HeaderTable<SimpleVO>(cols, 500){

			@Override
			public void onResizeBegin(ColWidget leftCol, ColWidget rightCol) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onResizeEnd(ColWidget leftCol, ColWidget rightCol) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onColVisibilityChanged(Cols<SimpleVO> visibleCols) {
				// TODO Auto-generated method stub
				
			}

		};
		return h;
	}
	*/
	public Widget initPortlet111(){
		Portlet p = new PortletAdapter();
		p.setPopupPosition(0, 0);
		p.setBodyWidget(new Label("sdsd"));
		p.setTitle("title");
		p.setSize("100px", "100px");
		p.show();
	
		Portlet p1 = new PortletAdapter();
		p1.setPopupPosition(100, 100);
		p1.setBodyWidget(new Label("sdsd"));
		p1.setTitle("title");
		p1.setSize("100px", "100px");
		p1.show();
		
		return new Label("sdsd");
	}
	
	public Widget initPortlet343(){
		
		PortletContainer pc = new PortletContainer(4,200);
		pc.addPortlet(0, new HTML(H.getArbitSentence(25, 10)), new Label("My title widget"));
		pc.addPortlet(0, new HTML(H.getArbitSentence(25, 10)));
		pc.addPortlet(0, new HTML(H.getArbitSentence(25, 10)));
		pc.addPortlet(0, new HTML(H.getArbitSentence(325, 10)));

		pc.addPortlet(1, new HTML(H.getArbitSentence(125, 10)), new HorizontalPanel(){
			{
				setBorderWidth(1);
				add(new Label("Header text") );
				add(new Anchor("[close]"));
				setWidth("100%");
			}
		});
		pc.addPortlet(1, new HTML(H.getArbitSentence(25, 10)));
		pc.addPortlet(1, new HTML(H.getArbitSentence(25, 10)));
		pc.addPortlet(1, new HTML(H.getArbitSentence(225, 10)));

		
		pc.addPortlet(2, new HTML(H.getArbitSentence(225, 10)));
		pc.addPortlet(2, new HTML(H.getArbitSentence(325, 10)));
		pc.addPortlet(2, new HTML(H.getArbitSentence(225, 10)));
		pc.addPortlet(2, new HTML(H.getArbitSentence(225, 10)));

		pc.addPortlet(3, new HTML(H.getArbitSentence(25, 10)));
		pc.addPortlet(3, new HTML(H.getArbitSentence(125, 10)));
		pc.addPortlet(3, new HTML(H.getArbitSentence(25, 10)));
		pc.addPortlet(3, new HTML(H.getArbitSentence(125, 10)));



		/*final VerticalPanel vPanel = new VerticalPanel();
		vPanel.setBorderWidth(1);
		Portlet p1 = new Portlet(){
			private int startX, startY; 
			@Override
			public void onDrag(int mouseX, int mouseY) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onDragEnd(int mouseX, int mouseY) {
				this.removeStyleName("position-absolute");
				setPopupPosition(startX, startY);
			}

			@Override
			public void onDragStart(int mouseX, int mouseY) {
				int startX = this.getPopupLeft();
				int startY = this.getPopupTop();
				this.addStyleName("position-absolute");
//				vPanel.remove(this);
				vPanel.setVisible(true);
			}
			
		};
		Dragger p2 = new Dragger(){

			@Override
			public void onDrag(int mouseX, int mouseY) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onDragEnd(int mouseX, int mouseY) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onDragStart(int mouseX, int clientY) {
				this.addStyleName("position-absolute");
//				vPanel.remove(this);
			}};
			p1.setWidget(new HTML("test widget 1"));
			p2.setWidget(new HTML("test widget 2"));
		vPanel.add(p1);
		vPanel.add(p2);
		return vPanel;*/
		return pc;
	}
	public Widget initClientSideTab(){
		Cols<SimpleVO> cols = new Cols<SimpleVO>(){
			{
				add(new SystemManagedComparableColWidget<SimpleVO, TextBox>("int col"){

					@Override
					public TextBox createColWidgetInstance() {
						return new TextBox();
					}

/*					@Override
					public TextDesc createDisplayText(SimpleVO data) {
						return new TextDesc(false, data.getIntCol()+"");
					}
*/
					@Override
					public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
						return UserTriggerEvent.MOUSE_MOVE;
					}

					@Override
					public boolean resetData(TextBox w, SimpleVO data) {
						data.setIntCol(Integer.parseInt(w.getValue()));
						return true;
					}

					@Override
					public void resetWidget(SimpleVO data, TextBox w) {
						w.setText(data.getIntCol() + "");
					}

					@Override
					public HorizontalAlignmentConstant alignment(SimpleVO data) {
						return HasHorizontalAlignment.ALIGN_CENTER;
					}

					public Comparable getComparableValue(SimpleVO data) {
						return data.getIntCol();
					}

					public TextDesc createDisplayText(SimpleVO data) {
						return new TextDesc(false, data.getIntCol()+"");
					}
					
				});
				add(new SystemManagedComparableColWidget<SimpleVO, TextBox>("col1"){

					@Override
					public TextBox createColWidgetInstance() {
						return new TextBox();
					}

					public TextDesc createDisplayText(SimpleVO data) {
						return new TextDesc(true, "<b>" + data.getStrCol() + "</b>");
						
					}

					@Override
					public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
						return UserTriggerEvent.MOUSE_CLICK;
					}

					@Override
					public boolean resetData(TextBox w, SimpleVO data) {
						data.setStrCol(w.getText());
						return true;
					}

					@Override
					public void resetWidget(SimpleVO data, TextBox w) {
						w.setText(data.getStrCol());
					}

					public Comparable getComparableValue(SimpleVO data) {
						return data.getStrCol();
					}
					
				});
				
				
				
				add(new SystemManagedColWidget<SimpleVO, TextBox>("System managed textbox"){
	//
					@Override
					public TextBox createColWidgetInstance() {
						return new TextBox();
					}
	//
					public TextDesc createDisplayText(SimpleVO data) {
						return new TextDesc(true, data.getStrCol());
					}
	//
					@Override
					public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
						return UserTriggerEvent.MOUSE_MOVE;
					}
	//
					@Override
					public boolean resetData(TextBox w, SimpleVO data) {
						data.setStrCol(w.getText());
						return true;
					}
	//
					@Override
					public void resetWidget(SimpleVO data, TextBox w) {
						w.setText(data.getStrCol());
					}
	//
					@Override
					public HorizontalAlignmentConstant alignment(SimpleVO data) {
						return HasHorizontalAlignment.ALIGN_CENTER;
					}
					
				});
			
				add(new UserManagedColWidget<SimpleVO, CheckBox>(colNames[1], 50){
	//
					public CheckBox createColWidgetInstance(final SimpleVO data) {
						final CheckBox chk = new CheckBox();
						chk.setValue(data.getIntCol() > 10);
						chk.addClickHandler(new ClickHandler(){
	//
							public void onClick(ClickEvent event) {
								data.setIntCol(chk.getValue()?5:12);
							}
							
						});
						return chk;
					}
					
					public HorizontalAlignmentConstant alignment() {
						return HasHorizontalAlignment.ALIGN_CENTER;
					}
	//
					/*public String defineColName() {
						return "user defined column";
					}*/
					
				});
			
				add(new SmartUserManagedColWidget<SimpleVO, TextBox>(colNames[2] ){
	//
					public TextBox createColWidgetInstance() {
						return new TextBox();
					}
	//
					public boolean resetData(TextBox w, SimpleVO data) {
						data.setStrCol(w.getText());
						return true;
					}
	//
					public void resetWidget(SimpleVO data, TextBox w) {
						w.setText(data.getStrCol());
					}
	//
					public HorizontalAlignmentConstant alignment() {
						return HasHorizontalAlignment.ALIGN_LEFT;
					}
	///*
					public String defineColName() {
						return "Smart user managed";
					}
				});
			
				
				add(new UserManagedColWidget<SimpleVO, TextBox>(colNames[4]){

					@Override
					public TextBox createColWidgetInstance(SimpleVO data) {
						TextBox t = new TextBox();
						t.setText(data.getStrCol());
						return t;
					}

				});				
			}
		};
		final ClientSideTableAdapter<SimpleVO> tab = new ClientSideTableAdapterWithEvents<SimpleVO>(cols, 400, 250, 23){};
		
		testService.fetchData(0, 100, null, false, new AsyncCallback<List<SimpleVO>>(){

			public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
			}

			public void onSuccess(List<SimpleVO> result) {
				tab.render(result);
			}
			
		});
		return tab;
	}
	
	public Widget initTab(){
		
		Cols<SimpleVO> cols = new Cols<SimpleVO>();

		
		ColWidget col1;
		
		
		cols.add(new SystemManagedColWidget<SimpleVO, FocusableDateBox>(colNames[3]){

			public FocusableDateBox createColWidgetInstance() {
				return new FocusableDateBox();
			}

			public TextDesc createDisplayText(SimpleVO data) {
				Date date = data.getDateCol();
				return new TextDesc(false, date == null?"":date.toString());
			}

			public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
				return UserTriggerEvent.MOUSE_CLICK;
			}

			public boolean resetData(FocusableDateBox w, SimpleVO data) {
				data.setDateCol(w.getValue());
				return false;
			}

			public void resetWidget(SimpleVO data, FocusableDateBox w) {
				w.setValue(data.getDateCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}
/*
			public String defineColName() {
				return "user defined column";
			}
			*/
		});
		
		cols.add(col1 = new ReadOnlyTextColWidget<SimpleVO>(colNames[0]){

			public TextDesc createDisplayText(SimpleVO data) {
				return new TextDesc(false, data.getStrCol());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}
/*
			public String defineColName() {
				return "read only column";
			}*/
			
		});
		
//		cols.add(new SystemManagedColWidget<SimpleVO, TextBox>("System managed textbox"){
//
//			@Override
//			public TextBox createColWidgetInstance() {
//				return new TextBox();
//			}
//
//			public TextDesc createDisplayText(SimpleVO data) {
//				return new TextDesc(true, data.getStrCol());
//			}
//
//			@Override
//			public org.gwtEss.table.SystemManagedColWidget.UserTriggerEvent flipWidgetEvent() {
//				return UserTriggerEvent.MOUSE_MOVE;
//			}
//
//			@Override
//			public boolean resetData(TextBox w, SimpleVO data) {
//				data.setStrCol(w.getText());
//				return true;
//			}
//
//			@Override
//			public void resetWidget(SimpleVO data, TextBox w) {
//				w.setText(data.getStrCol());
//			}
//
//			@Override
//			public HorizontalAlignmentConstant alignment(SimpleVO data) {
//				return HasHorizontalAlignment.ALIGN_CENTER;
//			}
//			
//		});
		
//		cols.add(new UserManagedColWidget<SimpleVO, CheckBox>(colNames[1], 30){
//
//			public CheckBox createColWidgetInstance(final SimpleVO data) {
//				final CheckBox chk = new CheckBox();
//				chk.setValue(data.getIntCol() > 10);
//				chk.addClickHandler(new ClickHandler(){
//
//					public void onClick(ClickEvent event) {
//						data.setIntCol(chk.getValue()?5:12);
//					}
//					
//				});
//				return chk;
//			}
//			
//			public HorizontalAlignmentConstant alignment() {
//				return HasHorizontalAlignment.ALIGN_CENTER;
//			}
//
//			/*public String defineColName() {
//				return "user defined column";
//			}*/
//			
//		});
		
//		cols.add(new SmartUserManagedColWidget<SimpleVO, TextBox>(colNames[2] ){
//
//			public TextBox createColWidgetInstance() {
//				return new TextBox();
//			}
//
//			public boolean resetData(TextBox w, SimpleVO data) {
//				data.setStrCol(w.getText());
//				return true;
//			}
//
//			public void resetWidget(SimpleVO data, TextBox w) {
//				w.setText(data.getStrCol());
//			}
//
//			public HorizontalAlignmentConstant alignment() {
//				return HasHorizontalAlignment.ALIGN_LEFT;
//			}
///*
//			public String defineColName() {
//				return "Smart user managed";
//			}
//			*/
//		});
	
		
		cols.add(new UserManagedColWidget<SimpleVO, TextBox>(colNames[4]){

			@Override
			public TextBox createColWidgetInstance(SimpleVO data) {
				TextBox t = new TextBox();
				t.setText(data.getStrCol());
				return t;
			}

		});
		final OnDemandTableAdapter<SimpleVO> tab = new OnDemandTableAdapter<SimpleVO>(cols, 500, 300, 20) {

			@Override
			public void fetchRowData(
					int startRow,
					int endRow,
					ColWidget sortCol,
					Boolean asc, Map<ColWidget, List<FilterMenuItem>> filters,
					final FetchCompleteCallBack<SimpleVO> fetchCompleteCallBack) {
				testService.fetchData(startRow, endRow, sortCol == null? null:sortCol.getColName(), asc, new AsyncCallback<List<SimpleVO>>(){

					public void onFailure(Throwable caught) {
						Window.alert(caught.toString());
					}

					public void onSuccess(List<SimpleVO> result) {
						fetchCompleteCallBack.onFetchComplete(result);
					}
					
				});
			}

	
			@Override
			public void fetchColumnUniqueValues(ColWidget col,
					final FetchCompleteCallBack<FilterMenuItem> filterListCallBack) {
				testService.fetchFilterList(col.getColName(), new AsyncCallback<List<FilterMenuItem>>(){

					public void onFailure(Throwable caught) {
						Window.alert(caught.getMessage());
					}

					public void onSuccess(List<FilterMenuItem> result) {
						filterListCallBack.onFetchComplete(result);
					}
					
				});
			}

		};
		tab.render(90);
		return tab;

	}
	
}
